#!/bin/bash
# ================================================================
# 使用 r50_deformable_detr_motip_smd_det.yaml 进行推理评估
# 默认复用 baseline 检查点（pretrains/smd_baseline.pth）
# 可选通过设置 RUN_LWG=1 + LWG_MODEL_PATH 来额外跑 LWG 版本
# ================================================================

set -euo pipefail

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${PROJECT_ROOT}"

CONFIG_PATH="${CONFIG_PATH:-${PROJECT_ROOT}/configs/r50_deformable_detr_motip_smd_det.yaml}"
CHECKPOINT_PATH="${CHECKPOINT_PATH:-${PROJECT_ROOT}/pretrains/smd_baseline.pth}"
OUTPUT_ROOT="${OUTPUT_ROOT:-${PROJECT_ROOT}/outputs/motip_smd_det_eval}"
DATA_ROOT="${DATA_ROOT:-/home/liuyonghui/datasets}"
LWG_MODEL_PATH="${LWG_MODEL_PATH:-${PROJECT_ROOT}/pretrains/lwg_smd.pt}"

RUN_LWG="${RUN_LWG:-0}"      # 0: 只跑 baseline；1: 额外跑 LWG

mkdir -p "${OUTPUT_ROOT}"

ARGS=(--config "${CONFIG_PATH}"
      --checkpoint "${CHECKPOINT_PATH}"
      --output-root "${OUTPUT_ROOT}"
      --data-root "${DATA_ROOT}")

if [[ "${RUN_LWG}" == "1" ]]; then
  ARGS+=(--lwg-model "${LWG_MODEL_PATH}")
else
  ARGS+=(--skip-lwg)
fi

echo "[Eval] config=${CONFIG_PATH}"
echo "[Eval] checkpoint=${CHECKPOINT_PATH}"
echo "[Eval] output=${OUTPUT_ROOT}"
echo "[Eval] data_root=${DATA_ROOT}"
echo "[Eval] run_lwg=${RUN_LWG}"

python compare_lwg.py "${ARGS[@]}"
